<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/personalCenter.css">
</head>
<body>
<!------IE浏览器判断------>
<!--[if lt IE 9]>
<script type="text/javascript" src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js">
</script>
<![endif]-->
<jsp:include page="head.jsp"></jsp:include>
<!------主内容区------>
<div class="main">
    <div class="poistion">
        <h4 class="clearfix">
            <span class="icon icon1"></span><span> 首页 > 个人中心 > 修改密码</span>
        </h4>
    </div>
    <div id="aside">
        <div class="aside-title">
            <h3>个人中心</h3>
        </div>
        <div class="aside-content">
            <ul class="itemlist">
                <li class="item"><a href="personlCenter.jsp">基本信息</a><span class="icon2"></span></li>
                <li class="item"><a href="personalChange.jsp">修改信息</a><span class="icon2"></span></li>
                <li class="item"><a href="changePassword.jsp">修改密码</a><span class="icon2"></span></li>
                <li class="item"><a href="replacement.jsp">会员升级</a><span class="icon2"></span></li>
            </ul>
        </div>
    </div>
    <div class="modal" id="newsLis">
        <div id="newsList">
            <div class="newsList-content">
                <div class="newsList-title">
                    <h3 class="pull-left left">修改密码</h3>
                    <i></i>
                </div>
                <div class="newList-main">
                    <div class="forms">
                        <form action="" id="formId">
                        <c:set var="cid" value="${comp.comp_id }"></c:set>
                            <table>
                                <tr>
                                    <th><span>*</span>原&nbsp;&nbsp;密&nbsp;&nbsp;码：</th>
                                    <td><input type="password" id="passwordes" name="oldpwd" placeholder="请输入您的密码" onblur="passWords()">
                                    </td>
                                    <td class="warning" id="passwordes-warn"></td>
                                </tr>
                                <tr>
                                    <th><span>*</span>密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</th>
                                    <td><input type="password" id="password" name="company.comp_pwd" placeholder="请输入您的密码" onblur="passWord()">
                                    </td>
                                    <td class="warning" id="password-warn"></td>
                                </tr>
                                <tr>
                                    <th><span>*</span>确认密码：</th>
                                    <td><input type="password" id="againword" placeholder="请再次输入密码"
                                               onblur="againWord()">
                                    </td>
                                    <td class="warning" id="againword-warn"></td>
                                </tr>
                            </table>
                            <input type="button" value="确认修改" class="submits" onclick="resetpwd()">
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="covers"></div>
<div id="alerts">
    <h3>提示</h3>
    <h4>mima</h4>

</div>
<!------页脚------>
<jsp:include page="foot.jsp"></jsp:include>
<!------JS部分------>
<script>
	//修改密码
	function resetpwd(){
		var data = $("#formId").serialize();
		var c = '${comp.comp_id}'; 
		
		var a = $("#passwordes").val();
        var reg1 = new RegExp("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$");
        var b = $("#password").val();
        var c = $("#againword").val();
        setTimeout('$("#alerts").fadeOut()', 2000);
        if (!a.match(reg1) || a == "") {
            popup($("#alerts"));
            $(" #alerts h4").text("请确认原密码格式！");
            return false
        }
        else if (!b.match(reg1) || b == "") {
            popup($("#alerts"));
            $(" #alerts h4").text("请确认新密码格式！");
            return false
        }
        else if (c != b) {
            popup($("#alerts"));
            $(" #alerts h4").text("请确认密码是否一致！");
            return false
        }
        
		$.post("company_resetpwd?"+data+"&company.comp_id=${cid}",function(data){
			if(data){
				$("#passwordes").val("");
	            $("#password").val("");
	            $("#againword").val("");
				 popup($("#alerts"));
		         $(" #alerts h4").text(data);
			}
		}); 
	}
	
    function check(id, reg, spanId, errorInfo) {
        var flag;
        var val = document.getElementById(id).value;
        var oSpanNode = document.getElementById(spanId);
        if (reg.test(val) && val != "") {
            oSpanNode.innerHTML = "";
            flag = true;
        } else {
            oSpanNode.innerHTML = errorInfo.fontcolor("#c93d00");
            flag = false;
        }

        return flag;
    }
    function passWord() {
        var reg = new RegExp("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$");
        check("password", reg, "password-warn", "密码至少输入6-16个字符，请使用英文字母和数字组合密码");
    }
    function passWords() {
        var reg = new RegExp("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$");
        check("passwordes", reg, "passwordes-warn", "密码至少输入6-16个字符，请使用英文字母和数字组合密码");
    }
    function againWord() {
        var flag;
        var rp = document.getElementById("againword").value;
        var ps = document.getElementById("password").value;
        var oSpanNodes = document.getElementById("againword-warn");
        if (rp == ps) {
            oSpanNodes.innerHTML = "";
            flag = true;
        }
        else {
            oSpanNodes.innerHTML = "请再次确认密码是否一致".fontcolor("#c93d00");
            flag = false;
        }
        return flag;
    }
  

	function popup(popupName) {
        var _scrollHeight = $(document).scrollTop(),//获取当前窗口距离页面顶部高度
            _windowHeight = $(window).height(),//获取当前窗口高度
            _windowWidth = $(window).width(),//获取当前窗口宽度
            _popupHeight = popupName.height(),//获取弹出层高度
            _popupWeight = popupName.width();//获取弹出层宽度
        _posiTop = (_windowHeight - _popupHeight-150) / 2 + _scrollHeight;
        _posiLeft = (_windowWidth - _popupWeight+300) / 2;
        popupName.css({"left": _posiLeft + "px", "top": _posiTop + "px", "display": "block"});//设置position
    }
</script>
</body>
</html>